<template>
  <el-dialog title="商品品种查询" :close-on-click-modal="false" :visible.sync="visible" fullscreen center append-to-body>
    <el-button class="miui-dialog-close-btn" @click="visible = false">关闭页面</el-button>
    <el-card class="box-card" style="margin-bottom: 15px;">
      <div class="text item">
        <el-form inline size="mini" label-width="90px">
          <el-form-item label="品种编码">
            <el-input v-model="dataForm.code"></el-input>
          </el-form-item>
          <el-form-item label="品种名称">
            <el-input v-model="dataForm.name"></el-input>
          </el-form-item>
          <el-form-item label="状态">
            <el-select v-model="dataForm.status">
              <el-option value="1" label="启用"></el-option>
              <el-option value="0" label="停用"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button icon="el-icon-search" type="info" plain @click="getDataListt">查询</el-button>
            <el-button icon="el-icon-delete" type="info" plain @click="clearSearchForm">清空</el-button>
          </el-form-item>
        </el-form>
      </div>
    </el-card>
    <el-table :data="dataList" height="calc(100vh - 215px)" ref="singleTable" border v-loading="dataListLoading">
      <el-table-column type="index" width="50">
        <template slot-scope="scope">
          <el-radio v-model="dataForm.supplyId" :label="scope.row.id" style="position: relative;left: 6px;top:-2px;" @change="checkitem(scope.row)">&nbsp;</el-radio>
        </template>
      </el-table-column>
      <el-table-column prop="code" label="品种编码"></el-table-column>
      <el-table-column prop="name" label="品种名称"></el-table-column>
      <el-table-column prop="ctgName" label="商品类别"></el-table-column>
      <el-table-column prop="supplyName" label="制造商"></el-table-column>
    </el-table>
    <div class="avue-crud__pagination">
      <el-pagination
        @size-change="sizeChangeHandle"
        @current-change="currentChangeHandle"
        :current-page="pageIndex"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="pageSize"
        :total="totalPage"
        background
        layout="total, sizes, prev, pager, next">
      </el-pagination>
    </div>
  </el-dialog>
</template>

<script>
  import {filterParams} from '@/util/tools'
  import {fetchBrandList} from '@/api/eims/brand'
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          supplyId: '',
          supplyCode: '',
          supplyName: '',
          ctgId: '',
          status: '',
          timestamp: ''
        },
        dataList: [],
        dataListLoading: false,
        pageIndex: 1,
        pageSize: 100,
        totalPage: 0
      }
    },
    methods: {
      init(data) {
        this.visible = true
        for(let key in this.dataForm){
          this.dataForm[key] = ''
        }
				this.formData = data.data
        this.dataForm.ctgId = data.ctgId
        this.dataForm.supplyId = data.supplyId
        this.getDataListt()
      },
			clearSearchForm() {
				for(let key in this.dataForm){
					this.dataForm[key] = ''
				}
			},
      getDataListt() {
        let params1 = {current: this.pageIndex,size: this.pageSize}
        let params2 = filterParams(this.dataForm)
        fetchBrandList(Object.assign(params1,params2)).then(response => {
          if(response.data.code == '0'){
            this.dataList = response.data.data.records
            this.totalPage = response.data.data.total
          }else{
            this.$message.error(response.data.msg)
          }
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataListt()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataListt()
      },
      // 选择品种
      checkitem(val) {
        this.visible = false
        this.formData.brandId = val.id
        this.formData.brandName = val.name
        this.$emit('refreshData',this.formData)
      },
    }
  }
</script>

<style>
</style>
